#ifndef __VZ_LIBUV_H__
#define __VZ_LIBUV_H__

#include <stdint.h>
#include <uv.h>
#include "userLog.h"
#include "minmea.h"

typedef struct
{
    uv_timer_t vzReq;
    uv_timer_t mainWorkSetTimeOut;
    uv_tcp_t vz_socket;
    uv_connect_t client;
} VzLibuvStruct;

typedef struct
{
    uint8_t vzAppStream[1024 * 1024];
    VzLibuvStruct uv;
    uint16_t vzCamPort;
    uint8_t vzCamIp[32];
    uint8_t vzCamId;
    bool isConnected;
    uint8_t recvResponseCount;
    uint8_t gga[MINMEA_MAX_LENGTH];
    uint8_t rmc[MINMEA_MAX_LENGTH];
    // 累计收到的包字节数
    ssize_t accumulate_recvLen;
    // 剩余需要收的字节数
    uint32_t reverse_pack_len;
    // 整包大小
    uint32_t hold_pack_len;
    uint32_t hold_pack_len_tmp;
    // 下次需要收的缓存字节数
    ssize_t nextBufSize;
    // 是否处理了识别结果包接下来要接收的字节数
    bool isHandleIvsPackSize;
    // 是否参与标定v2
    bool isCalibration;
    // 备注
    uint8_t remark[256];
} VzAppStruct;

void vzInterval(void *cb, uint16_t time);
void vzConnect(uv_connect_cb cb);
void vzClearInterval();

void vzSetTimeout(void *cb, uint16_t time);

VzAppStruct *getVzAppPtrFromUvConnect(uv_connect_t *client);
VzAppStruct *getVzAppPtrFromUvStream(uv_stream_t *stream);
VzAppStruct *getVzAppPtrFromUvTimmerInterval(uv_timer_t *timmer);
VzAppStruct *getVzAppPtrFromUvTimmerSetTimeOut(uv_timer_t *timmer);

void setPrivateVzlibuvStruct(VzLibuvStruct *vzLibStruct);

#endif